<template>
  <div class="data-screen">
    <!-- 头部标题 -->
    <div class="header">
      <div class="header-left">
        <div class="logo-icon">🌲</div>
        <h1 class="title">晋江市林地指标交易平台</h1>
      </div>
      <div class="header-right">
        <div class="refresh-container">
          <button
            @click="refreshAllData"
            :disabled="loading"
            class="refresh-btn"
          >
            <span class="refresh-icon" :class="{ spinning: loading }">🔄</span>
            <span class="refresh-text">{{
              loading ? "刷新中..." : "刷新数据"
            }}</span>
          </button>
        </div>
        <div class="time-container">
          <div class="time-label">当前时间</div>
          <div class="time">{{ currentTime }}</div>
        </div>
      </div>
    </div>

    <!-- 主要内容区域 -->
    <div class="main-content">
      <!-- 顶部统计卡片 -->
      <div class="top-stats">
        <div class="stat-card">
          <div class="stat-icon">💰</div>
          <div class="stat-content">
            <div class="stat-value">{{ totalAmount }}万元</div>
            <div class="stat-label">平台累计交易额</div>
          </div>
        </div>
        <div class="stat-card">
          <div class="stat-icon">📋</div>
          <div class="stat-content">
            <div class="stat-value">{{ totalOrders }}笔</div>
            <div class="stat-label">累计成交订单量</div>
          </div>
        </div>
        <div class="stat-card">
          <div class="stat-icon">🏢</div>
          <div class="stat-content">
            <div class="stat-value">{{ totalCompanies }}家</div>
            <div class="stat-label">累计注册企业</div>
          </div>
        </div>
        <div class="stat-card">
          <div class="stat-icon">🌳</div>
          <div class="stat-content">
            <div class="stat-value">{{ totalArea }}亩</div>
            <div class="stat-label">总林地面积</div>
          </div>
        </div>
      </div>

      <!-- 中间内容区域 -->
      <div class="middle-content">
        <!-- 左侧图表区域 -->
        <div class="left-container">
          <!-- 各街道镇区林地面积情况 -->
          <div class="chart-box">
            <div class="box-title">各街道镇区林地面积情况</div>
            <div ref="areaChart" class="chart"></div>
          </div>

          <!-- 各镇区街道林地面积交易情况 -->
          <div class="chart-box">
            <div class="box-title">各镇区街道林地面积交易情况</div>
            <div ref="tradeChart" class="chart"></div>
          </div>

          <!-- 资金营收统计 -->
          <div class="chart-box">
            <div class="box-title">资金营收统计</div>
            <div ref="revenueChart" class="chart"></div>
          </div>
        </div>

        <!-- 中间地图区域 -->
        <div class="center-container">
          <div class="map-box">
            <div class="box-title">晋江市林地分布图</div>
            <div ref="mapChart" class="map-chart"></div>
          </div>
        </div>

        <!-- 右侧图表区域 -->
        <div class="right-container">
          <!-- 林地补贴申请统计 -->
          <div class="chart-box">
            <div class="box-title">林地补贴申请统计</div>
            <div ref="subsidyChart" class="chart"></div>
          </div>

          <!-- 企业信息注册统计 -->
          <div class="chart-box">
            <div class="box-title">企业信息注册统计</div>
            <div ref="companyChart" class="chart"></div>
          </div>

          <!-- 交易订单统计 -->
          <div class="chart-box">
            <div class="box-title">交易订单统计</div>
            <div ref="orderChart" class="chart"></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
import * as echarts from "echarts";
import jinjiangMapData from "~/assets/350582.json";
import {
  getPlatformOverviewApi,
  getAreaStatisticsApi,
  getTradeStatisticsApi,
  getRevenueStatisticsApi,
  getMapDataApi,
  getSubsidyStatisticsApi,
  getCompanyStatisticsApi,
  getOrderStatisticsApi,
} from "~/api/lindi/dashboard.js";

// 响应式数据
const currentTime = ref("");
const totalAmount = ref("0.0");
const totalOrders = ref("0");
const totalCompanies = ref("0");
const totalArea = ref("0.0");

// 数据加载状态
const loading = ref(false);

// 加载平台概览数据
const loadPlatformOverview = () => {
  return getPlatformOverviewApi()
    .then((response) => {
      const data = response;
      totalAmount.value = data.totalAmount || "0.0";
      totalOrders.value = data.totalOrders || "0";
      totalCompanies.value = data.totalCompanies || "0";
      totalArea.value = data.totalArea || "0.0";
    })
    .catch((error) => {
      console.error("加载平台概览数据失败:", error);
    });
};

// 图表引用
const areaChart = ref(null);
const tradeChart = ref(null);
const revenueChart = ref(null);
const mapChart = ref(null);
const subsidyChart = ref(null);
const companyChart = ref(null);
const orderChart = ref(null);

// 图表实例
let areaChartInstance = null;
let tradeChartInstance = null;
let revenueChartInstance = null;
let mapChartInstance = null;
let subsidyChartInstance = null;
let companyChartInstance = null;
let orderChartInstance = null;

// 更新时间
const updateTime = () => {
  const now = new Date();
  currentTime.value = now.toLocaleString("zh-CN", {
    year: "numeric",
    month: "2-digit",
    day: "2-digit",
    hour: "2-digit",
    minute: "2-digit",
    second: "2-digit",
  });
};

// 初始化各街道镇区林地面积图表
const initAreaChart = () => {
  areaChartInstance = echarts.init(areaChart.value);

  return getAreaStatisticsApi()
    .then((response) => {
      return response || [];
    })
    .catch((error) => {
      console.error("加载面积统计数据失败:", error);
      return [];
    })
    .then((areaData) => {
      const option = {
        tooltip: {
          trigger: "axis",
          axisPointer: { type: "shadow" },
          backgroundColor: "rgba(0, 0, 0, 0.8)",
          borderColor: "#4caf50",
          textStyle: { color: "#fff", fontSize: 12 },
        },
        grid: {
          left: "8%",
          right: "4%",
          bottom: "25%",
          top: "10%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: areaData.map((item) => item.name),
          axisLabel: {
            color: "#e8f5e8",
            fontSize: 10,
            fontWeight: "500",
            interval: 0,
            rotate: 45,
          },
          axisLine: { lineStyle: { color: "#4caf50", width: 2 } },
          axisTick: { lineStyle: { color: "#4caf50" } },
        },
        yAxis: {
          type: "value",
          name: "面积(亩)",
          nameTextStyle: { color: "#e8f5e8", fontSize: 12 },
          axisLabel: { color: "#e8f5e8", fontSize: 11 },
          axisLine: { lineStyle: { color: "#4caf50", width: 2 } },
          splitLine: { lineStyle: { color: "#2d5a42", type: "dashed" } },
        },
        dataZoom: [
          {
            type: "slider",
            show: true,
            xAxisIndex: [0],
            start: 0,
            end: 50,
            bottom: "5%",
            height: 20,
            backgroundColor: "rgba(76, 175, 80, 0.1)",
            fillerColor: "rgba(76, 175, 80, 0.3)",
            borderColor: "#4caf50",
            textStyle: { color: "#fff" },
          },
        ],
        series: [
          {
            name: "林地面积",
            type: "bar",
            data: areaData.map((item) => item.value),
            barWidth: "60%",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#66bb6a" },
                { offset: 0.5, color: "#4caf50" },
                { offset: 1, color: "#388e3c" },
              ]),
              borderRadius: [4, 4, 0, 0],
            },
            emphasis: {
              itemStyle: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  { offset: 0, color: "#81c784" },
                  { offset: 1, color: "#4caf50" },
                ]),
              },
            },
          },
        ],
      };
      areaChartInstance.setOption(option);
    });
};

// 初始化各镇区街道林地面积交易图表
const initTradeChart = () => {
  tradeChartInstance = echarts.init(tradeChart.value);

  return getTradeStatisticsApi()
    .then((response) => {
      return response || [];
    })
    .catch((error) => {
      console.error("加载交易统计数据失败:", error);
      return [];
    })
    .then((tradeData) => {
      const option = {
        tooltip: {
          trigger: "axis",
          axisPointer: { type: "cross" },
          backgroundColor: "rgba(0, 0, 0, 0.8)",
          borderColor: "#4caf50",
          textStyle: { color: "#fff", fontSize: 12 },
        },
        legend: {
          data: ["已交易面积", "可交易面积"],
          textStyle: { color: "#e8f5e8", fontSize: 12 },
          top: "5%",
        },
        grid: {
          left: "8%",
          right: "4%",
          bottom: "25%",
          top: "20%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: tradeData.map((item) => item.name),
          axisLabel: {
            color: "#e8f5e8",
            fontSize: 10,
            fontWeight: "500",
            interval: 0,
            rotate: 45,
          },
          axisLine: { lineStyle: { color: "#4caf50", width: 2 } },
          axisTick: { lineStyle: { color: "#4caf50" } },
        },
        yAxis: {
          type: "value",
          name: "面积(亩)",
          nameTextStyle: { color: "#e8f5e8", fontSize: 12 },
          axisLabel: { color: "#e8f5e8", fontSize: 11 },
          axisLine: { lineStyle: { color: "#4caf50", width: 2 } },
          splitLine: { lineStyle: { color: "#2d5a42", type: "dashed" } },
        },
        dataZoom: [
          {
            type: "slider",
            show: true,
            xAxisIndex: [0],
            start: 0,
            end: 50,
            bottom: "5%",
            height: 20,
            backgroundColor: "rgba(76, 175, 80, 0.1)",
            fillerColor: "rgba(76, 175, 80, 0.3)",
            borderColor: "#4caf50",
            textStyle: { color: "#fff" },
          },
        ],
        series: [
          {
            name: "已交易面积",
            type: "bar",
            stack: "total",
            data: tradeData.map((item) => item.traded),
            barWidth: "60%",
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#ff7043" },
                { offset: 1, color: "#d32f2f" },
              ]),
              borderRadius: [0, 0, 0, 0],
            },
          },
          {
            name: "可交易面积",
            type: "bar",
            stack: "total",
            data: tradeData.map((item) => item.available),
            itemStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "#66bb6a" },
                { offset: 1, color: "#388e3c" },
              ]),
              borderRadius: [4, 4, 0, 0],
            },
          },
        ],
      };
      tradeChartInstance.setOption(option);
    });
};

// 初始化资金营收图表
const initRevenueChart = () => {
  revenueChartInstance = echarts.init(revenueChart.value);

  return getRevenueStatisticsApi()
    .then((response) => {
      return response || [];
    })
    .catch((error) => {
      console.error("加载营收统计数据失败:", error);
      return [];
    })
    .then((revenueData) => {
      const option = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
          textStyle: { color: "#fff" },
        },
        series: [
          {
            name: "资金营收",
            type: "pie",
            radius: ["40%", "70%"],
            center: ["60%", "50%"],
            data: revenueData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      revenueChartInstance.setOption(option);
    });
};

// 初始化地图
const initMapChart = () => {
  echarts.registerMap("jinjiang", jinjiangMapData);
  mapChartInstance = echarts.init(mapChart.value);

  return getMapDataApi()
    .then((response) => {
      console.log("地图数据", response);
      return response || [];
    })
    .catch((error) => {
      console.error("加载地图数据失败:", error);
      return [];
    })
    .then((mapData) => {
      const option = {
        tooltip: {
          trigger: "item",
          formatter: function (params) {
            const data = params.data || {};
            return `${params.name}<br/>总面积: ${
              data.totalArea || 0
            }亩<br/>已交易: ${data.tradedArea || 0}亩<br/>可交易: ${
              data.availableArea || 0
            }亩`;
          },
        },
        visualMap: {
          min: 0,
          max: Math.max(
            2500,
            ...(Array.isArray(mapData)
              ? mapData.map((item) => parseFloat(item.totalArea) || 0)
              : [0])
          ),
          left: "left",
          top: "bottom",
          text: ["高", "低"],
          textStyle: { color: "#fff", fontSize: 12 },
          calculable: true,
          inRange: {
            color: [
              "#2d5a42",
              "#388e3c",
              "#4caf50",
              "#66bb6a",
              "#81c784",
              "#a5d6a7",
            ],
          },
          outOfRange: {
            color: ["#666666"],
          },
        },
        series: [
          {
            name: "林地面积",
            type: "map",
            map: "jinjiang",
            roam: true,
            zoom: 1.2,
            emphasis: {
              label: { show: true, color: "#fff", fontSize: 12 },
              itemStyle: {
                areaColor: "#4caf50",
                borderWidth: 2,
                borderColor: "#fff",
              },
            },
            label: {
              show: true,
              color: "#fff",
              fontSize: 10,
              fontWeight: "bold",
            },
            itemStyle: {
              borderColor: "#2d5a42",
              borderWidth: 1,
              areaColor: "#666666", // 无数据时的默认颜色
            },
            data: Array.isArray(mapData)
              ? mapData.map((item) => ({
                  name: item.name,
                  value: parseFloat(item.totalArea) || 0,
                  totalArea: item.totalArea,
                  tradedArea: item.tradedArea,
                  availableArea: item.availableArea,
                }))
              : [],
          },
        ],
      };
      mapChartInstance.setOption(option);
    });
};

// 初始化林地补贴申请图表
const initSubsidyChart = () => {
  subsidyChartInstance = echarts.init(subsidyChart.value);

  return getSubsidyStatisticsApi()
    .then((response) => {
      return response || [];
    })
    .catch((error) => {
      console.error("加载补贴统计数据失败:", error);
      return [];
    })
    .then((subsidyData) => {
      const option = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
          textStyle: { color: "#fff" },
        },
        series: [
          {
            name: "林地补贴申请",
            type: "pie",
            radius: "70%",
            center: ["60%", "50%"],
            data: subsidyData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      subsidyChartInstance.setOption(option);
    });
};

// 初始化企业信息注册图表
const initCompanyChart = () => {
  companyChartInstance = echarts.init(companyChart.value);

  return getCompanyStatisticsApi()
    .then((response) => {
      return response || [];
    })
    .catch((error) => {
      console.error("加载企业统计数据失败:", error);
      return [];
    })
    .then((companyData) => {
      const option = {
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)",
        },
        legend: {
          orient: "vertical",
          left: "left",
          textStyle: { color: "#fff" },
        },
        series: [
          {
            name: "企业注册",
            type: "pie",
            radius: "70%",
            center: ["60%", "50%"],
            data: companyData,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: "rgba(0, 0, 0, 0.5)",
              },
            },
          },
        ],
      };
      companyChartInstance.setOption(option);
    });
};

// 初始化交易订单统计图表
const initOrderChart = () => {
  orderChartInstance = echarts.init(orderChart.value);

  return getOrderStatisticsApi()
    .then((response) => {
      return response || {};
    })
    .catch((error) => {
      console.error("加载订单统计数据失败:", error);
      return {
        months: [],
        orders: [],
      };
    })
    .then((orderData) => {
      const option = {
        tooltip: {
          trigger: "axis",
          axisPointer: { type: "line" },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: {
          type: "category",
          data: orderData.months || [],
          axisLabel: { color: "#fff", fontSize: 10 },
          axisLine: { lineStyle: { color: "#4caf50" } },
        },
        yAxis: {
          type: "value",
          name: "订单数",
          axisLabel: { color: "#fff", fontSize: 10 },
          axisLine: { lineStyle: { color: "#4caf50" } },
          splitLine: { lineStyle: { color: "#2d5a42" } },
        },
        series: [
          {
            name: "交易订单",
            type: "line",
            smooth: true,
            data: orderData.orders || [],
            itemStyle: { color: "#4caf50" },
            lineStyle: { color: "#4caf50", width: 3 },
            areaStyle: {
              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                { offset: 0, color: "rgba(76, 175, 80, 0.3)" },
                { offset: 1, color: "rgba(76, 175, 80, 0.1)" },
              ]),
            },
          },
        ],
      };
      orderChartInstance.setOption(option);
    });
};

// 窗口大小改变时重新调整图表
const handleResize = () => {
  areaChartInstance?.resize();
  tradeChartInstance?.resize();
  revenueChartInstance?.resize();
  mapChartInstance?.resize();
  subsidyChartInstance?.resize();
  companyChartInstance?.resize();
  orderChartInstance?.resize();
};

// 定时器
let timeInterval = null;

// 刷新所有数据
const refreshAllData = async () => {
  if (loading.value) return;

  loading.value = true;
  try {
    // 并行加载所有数据
    await Promise.all([
      loadPlatformOverview(),
      refreshAreaChart(),
      refreshTradeChart(),
      refreshRevenueChart(),
      refreshMapChart(),
      refreshSubsidyChart(),
      refreshCompanyChart(),
      refreshOrderChart(),
    ]);
  } catch (error) {
    console.error("数据刷新失败:", error);
  } finally {
    loading.value = false;
  }
};

// 刷新面积图表
const refreshAreaChart = () => {
  return getAreaStatisticsApi()
    .then((response) => {
      const areaData = response || [];
      if (areaChartInstance) {
        areaChartInstance.setOption({
          xAxis: {
            data: areaData.map((item) => item.name),
          },
          series: [
            {
              data: areaData.map((item) => item.value),
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新面积统计数据失败:", error);
    });
};

// 刷新交易图表
const refreshTradeChart = () => {
  return getTradeStatisticsApi()
    .then((response) => {
      const tradeData = response || [];
      if (tradeChartInstance) {
        tradeChartInstance.setOption({
          xAxis: {
            data: tradeData.map((item) => item.name),
          },
          series: [
            {
              data: tradeData.map((item) => item.traded),
            },
            {
              data: tradeData.map((item) => item.available),
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新交易统计数据失败:", error);
    });
};

// 刷新营收图表
const refreshRevenueChart = () => {
  return getRevenueStatisticsApi()
    .then((response) => {
      const revenueData = response || [];
      if (revenueChartInstance) {
        revenueChartInstance.setOption({
          series: [
            {
              data: revenueData,
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新营收统计数据失败:", error);
    });
};

// 刷新地图
const refreshMapChart = () => {
  return getMapDataApi()
    .then((response) => {
      const mapData = response || [];
      if (mapChartInstance) {
        mapChartInstance.setOption({
          series: [
            {
              data: Array.isArray(mapData)
                ? mapData.map((item) => ({
                    name: item.name,
                    value: parseFloat(item.totalArea) || 0,
                    totalArea: item.totalArea,
                    tradedArea: item.tradedArea,
                    availableArea: item.availableArea,
                  }))
                : [],
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新地图数据失败:", error);
    });
};

// 刷新补贴图表
const refreshSubsidyChart = () => {
  return getSubsidyStatisticsApi()
    .then((response) => {
      const subsidyData = response || [];
      if (subsidyChartInstance) {
        subsidyChartInstance.setOption({
          series: [
            {
              data: subsidyData,
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新补贴统计数据失败:", error);
    });
};

// 刷新企业图表
const refreshCompanyChart = () => {
  return getCompanyStatisticsApi()
    .then((response) => {
      const companyData = response || [];
      if (companyChartInstance) {
        companyChartInstance.setOption({
          series: [
            {
              data: companyData,
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新企业统计数据失败:", error);
    });
};

// 刷新订单图表
const refreshOrderChart = () => {
  return getOrderStatisticsApi()
    .then((response) => {
      const orderData = response || { months: [], orders: [] };
      if (orderChartInstance) {
        orderChartInstance.setOption({
          xAxis: {
            data: orderData.months || [],
          },
          series: [
            {
              data: orderData.orders || [],
            },
          ],
        });
      }
    })
    .catch((error) => {
      console.error("刷新订单统计数据失败:", error);
    });
};

onMounted(() => {
  // 初始化时间
  updateTime();
  timeInterval = setInterval(updateTime, 1000);

  // 加载平台概览数据
  loadPlatformOverview()
    .then(() => {
      // 延迟初始化图表以确保DOM已渲染
      return new Promise((resolve) => {
        setTimeout(() => {
          // 初始化所有图表
          Promise.all([
            initAreaChart(),
            initTradeChart(),
            initRevenueChart(),
            initMapChart(),
            initSubsidyChart(),
            initCompanyChart(),
            initOrderChart(),
          ])
            .then(() => {
              // 图表初始化完成后添加resize监听器
              window.addEventListener("resize", handleResize);

              resolve();
            })
            .catch((error) => {
              console.error("图表初始化失败:", error);
              resolve();
            });
        }, 100);
      });
    })
    .catch((error) => {
      console.error("初始化失败:", error);
    });
});

onUnmounted(() => {
  // 清理定时器
  if (timeInterval) {
    clearInterval(timeInterval);
  }

  // 移除resize监听器
  window.removeEventListener("resize", handleResize);

  // 销毁图表实例
  areaChartInstance?.dispose();
  tradeChartInstance?.dispose();
  revenueChartInstance?.dispose();
  mapChartInstance?.dispose();
  subsidyChartInstance?.dispose();
  companyChartInstance?.dispose();
  orderChartInstance?.dispose();

  // 移除事件监听
  window.removeEventListener("resize", handleResize);
});
</script>

<style scoped>
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap");

.data-screen {
  width: 100vw;
  height: 100vh;
  min-height: 800px;
  background: linear-gradient(
    135deg,
    #0a1f0f 0%,
    #1a3d2e 30%,
    #2d5a42 70%,
    #3e7b5a 100%
  );
  color: #fff;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow-x: hidden;
  overflow-y: auto;
  position: relative;
  min-width: 320px;
}

.data-screen::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: radial-gradient(
      circle at 15% 15%,
      rgba(76, 175, 80, 0.15) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 85% 85%,
      rgba(129, 199, 132, 0.12) 0%,
      transparent 40%
    ),
    radial-gradient(
      circle at 50% 30%,
      rgba(102, 187, 106, 0.08) 0%,
      transparent 35%
    ),
    radial-gradient(
      circle at 30% 70%,
      rgba(165, 214, 167, 0.06) 0%,
      transparent 30%
    );
  pointer-events: none;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(15px);
  border-bottom: 3px solid rgba(76, 175, 80, 0.4);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 32px;
  filter: drop-shadow(0 0 10px rgba(76, 175, 80, 0.6));
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

.title {
  font-size: clamp(18px, 4vw, 32px);
  font-weight: 700;
  background: linear-gradient(45deg, #66bb6a, #4caf50, #81c784);
  background-size: 200% 200%;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 3s ease-in-out infinite;
  margin: 0;
  letter-spacing: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes gradientShift {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

.header-right {
  display: flex;
  align-items: center;
  gap: 15px;
}

.refresh-container {
  display: flex;
  align-items: center;
}

.refresh-btn {
  display: flex;
  align-items: center;
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, #4caf50, #388e3c);
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(76, 175, 80, 0.3);
  border: 1px solid rgba(76, 175, 80, 0.4);
}

.refresh-btn:hover:not(:disabled) {
  background: linear-gradient(135deg, #66bb6a, #4caf50);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(76, 175, 80, 0.4);
  border-color: rgba(76, 175, 80, 0.6);
}

.refresh-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(76, 175, 80, 0.3);
}

.refresh-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.refresh-icon {
  margin-right: 6px;
  font-size: 14px;
  transition: transform 0.3s ease;
}

.refresh-icon.spinning {
  animation: spin 1s linear infinite;
}

.refresh-text {
  white-space: nowrap;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.time-container {
  text-align: right;
}

.time-label {
  font-size: 12px;
  color: #a5d6a7;
  font-weight: 400;
  margin-bottom: 2px;
}

.time {
  font-size: clamp(12px, 2vw, 14px);
  color: #4caf50;
  font-weight: 600;
  font-family: "Courier New", monospace;
  text-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
  white-space: nowrap;
}

.main-content {
  padding: 15px;
  min-height: calc(100vh - 100px);
  height: auto;
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.top-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 10px;
}

.stat-card {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(15px);
  border: 2px solid rgba(76, 175, 80, 0.3);
  border-radius: 16px;
  padding: 15px;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(76, 175, 80, 0.15),
    transparent
  );
  transition: left 0.6s ease;
}

.stat-card:hover {
  transform: translateY(-5px);
  border-color: rgba(76, 175, 80, 0.6);
  box-shadow: 0 10px 30px rgba(76, 175, 80, 0.2);
}

.stat-card:hover::before {
  left: 100%;
}

.stat-icon {
  font-size: clamp(24px, 5vw, 28px);
  filter: drop-shadow(0 0 8px rgba(76, 175, 80, 0.5));
  flex-shrink: 0;
}

.stat-content {
  flex: 1;
}

.stat-value {
  font-size: clamp(20px, 4vw, 28px);
  font-weight: 700;
  color: #4caf50;
  margin-bottom: 3px;
  text-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
  word-break: break-all;
}

.stat-label {
  font-size: clamp(10px, 2vw, 12px);
  color: #b8e6b8;
  font-weight: 500;
  line-height: 1.3;
}

.stat-trend {
  font-size: clamp(10px, 1.5vw, 14px);
  color: #81c784;
  font-weight: 600;
  background: rgba(76, 175, 80, 0.1);
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(76, 175, 80, 0.3);
  white-space: nowrap;
}

.middle-content {
  display: grid;
  grid-template-columns: 1fr 1.5fr 1fr;
  gap: clamp(12px, 1.8vw, 20px);
  min-height: 600px;
  height: auto;
  flex: 1;
}

.left-container,
.right-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  min-width: 0;
}

.left-container::-webkit-scrollbar,
.right-container::-webkit-scrollbar {
  display: none;
}

.center-container {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chart-box,
.map-box {
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(15px);
  border: 2px solid rgba(76, 175, 80, 0.3);
  border-radius: 16px;
  padding: 15px;
  flex: 1;
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
  min-height: 300px;
  min-width: 0;
}

.chart-box:hover,
.map-box:hover {
  border-color: rgba(76, 175, 80, 0.5);
  box-shadow: 0 8px 25px rgba(76, 175, 80, 0.15);
}

.map-box {
  height: 100%;
}

.box-title {
  font-size: clamp(14px, 2.5vw, 16px);
  font-weight: 600;
  color: #4caf50;
  margin-bottom: 15px;
  text-align: center;
  position: relative;
  letter-spacing: 0.5px;
}

.box-title::after {
  content: "";
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 3px;
  background: linear-gradient(90deg, #4caf50, #81c784, #4caf50);
  border-radius: 2px;
}

.chart {
  height: 140px;
  width: 100%;
}

.map-chart {
  height: calc(100% - 60px);
  width: 100%;
}

/* 响应式设计优化 */
@media (max-width: 1600px) {
  .header {
    padding: 0 30px;
  }

  .main-content {
    padding: 15px;
  }

  .stat-card {
    padding: 20px;
  }
}

@media (max-width: 1200px) {
  .middle-content {
    grid-template-columns: 1fr;
  }

  .left-container,
  .right-container {
    flex-direction: row;
    gap: 15px;
  }

  .chart-box,
  .map-box {
    min-height: 280px;
  }
}

@media (max-width: 1024px) {
  .header {
    height: 70px;
    padding: 0 20px;
  }

  .main-content {
    min-height: calc(100vh - 70px);
    height: auto;
    padding: 15px;
    gap: 15px;
  }

  .top-stats {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
  }

  .stat-card {
    padding: 16px;
  }

  .chart-box,
  .map-box {
    padding: 15px;
    min-height: 250px;
  }

  .bottom-content {
    min-height: 180px;
  }
}

@media (max-width: 768px) {
  .header {
    height: 60px;
    padding: 0 15px;
  }

  .header-left {
    gap: 12px;
  }

  .logo-icon {
    font-size: 20px;
  }

  .main-content {
    min-height: calc(100vh - 60px);
    height: auto;
    padding: 10px;
    gap: 15px;
  }

  .top-stats {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
  }

  .stat-card {
    padding: 12px;
  }

  .middle-content {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .left-container,
  .right-container {
    flex-direction: column;
    gap: 15px;
  }

  .chart-box,
  .map-box {
    padding: 15px;
    min-height: 220px;
  }
}

@media (max-width: 480px) {
  .header {
    height: 50px;
    padding: 0 10px;
  }

  .header-left {
    gap: 8px;
  }

  .logo-icon {
    font-size: 16px;
  }

  .main-content {
    min-height: calc(100vh - 50px);
    height: auto;
    padding: 8px;
    gap: 10px;
  }

  .top-stats {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
  }

  .stat-card {
    padding: 10px;
  }

  .middle-content {
    gap: 10px;
  }

  .left-container,
  .right-container {
    gap: 10px;
  }

  .chart-box,
  .map-box {
    padding: 10px;
    min-height: 180px;
  }
}

@media (max-width: 360px) {
  .top-stats {
    grid-template-columns: 1fr;
  }

  .stat-card {
    padding: 8px;
  }

  .chart-box,
  .map-box {
    padding: 8px;
    min-height: 160px;
  }
}

/* 横屏适配 */
@media (orientation: landscape) and (max-height: 600px) {
  .header {
    height: 50px;
  }

  .main-content {
    min-height: calc(100vh - 50px);
    height: auto;
    padding: 10px;
    gap: 10px;
  }

  .top-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 5px;
  }

  .stat-card {
    padding: 8px;
  }

  .middle-content {
    grid-template-columns: 1fr 1.5fr 1fr;
    gap: 10px;
  }

  .left-container,
  .right-container {
    flex-direction: column;
    gap: 10px;
  }

  .chart-box,
  .map-box {
    padding: 10px;
    min-height: 150px;
  }
}

/* 全局滚动条隐藏 */
html,
body {
  overflow-x: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  display: none;
}

/* 动画效果 */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.2);
    opacity: 0.7;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.chart-box,
.map-box,
.data-box,
.stat-card {
  animation: fadeInUp 0.6s ease-out;
}

.chart-box:nth-child(2) {
  animation-delay: 0.1s;
}

.chart-box:nth-child(3) {
  animation-delay: 0.2s;
}

.map-box {
  animation-delay: 0.15s;
}
</style>
